<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>全局空间</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="language.namespaces.importing.html">« 使用命名空间：别名/导入</a></li>
      <li style="float: right;"><a href="language.namespaces.fallback.html">使用命名空间：后备全局函数/常量 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="language.namespaces.html">命名空间</a></li>
    <li>全局空间</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="language.namespaces.global" class="sect1">
  <h2 class="title">全局空间</h2>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p>
  <p class="para">
   如果没有定义任何命名空间，所有的类与函数的定义都是在全局空间，与 
   PHP 引入命名空间概念前一样。在名称前加上前缀 <code class="literal">\</code>
   表示该名称是全局空间中的名称，即使该名称位于其它的命名空间中时也是如此。
   <div class="example" id="example-313">
    <p><strong>示例 #1 使用全局空间说明</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">\</span><span style="color: #0000BB">B</span><span style="color: #007700">\</span><span style="color: #0000BB">C</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;这个函数是&nbsp;A\B\C\fopen&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">()&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;...&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$f&nbsp;</span><span style="color: #007700">=&nbsp;\</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(...);&nbsp;</span><span style="color: #FF8000">//&nbsp;调用全局的fopen函数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">$f</span><span style="color: #007700">;<br />}&nbsp;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div></div></div></body></html>